import java.util.Arrays;

/**
 * Created with Intellij JDEA
 * Description:
 * User:
 * Date:2022-04-22
 * Time:18:09
 */
public class 旋转函数 {
    class Solution {

        public int maxRotateFunction(int[] nums) {
            int f = 0, n = nums.length, numSum = Arrays.stream(nums).sum();
            for (int i = 0; i < n; i++) {
                f += i * nums[i];
            }
            int res = f;
            for (int i = n - 1; i > 0; i--) {
                f += numSum - n * nums[i];
                res = Math.max(res, f);
            }
            return res;
        }
    }
}
